package com.woniuxy.woniuticket.movieinfomodule.controller;

import com.github.pagehelper.Page;
import com.woniuxy.woniuticket.movieinfomodule.dto.UserandVip;
import com.woniuxy.woniuticket.movieinfomodule.service.impl.CinemaVipServiceImp;
import com.woniuxy.woniuticket.movieinfomodule.service.impl.UserVipInfoServiceImp;
import com.woniuxy.woniuticket.pojo.CinemaVip;
import com.woniuxy.woniuticket.pojo.UsersInfo;
import com.woniuxy.woniuticket.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zyf
 * @Description:TODO
 * @date 2019/6/10
 * @Version 1.0
 */
@Controller
public class ManagerVipController {
    @Autowired
    private UserVipInfoServiceImp userVipInfoServiceImp;
    @Autowired
    private CinemaVipServiceImp cinemaVipServiceImp;

    //获取所有用户信息
    @RequestMapping("/vip/allVipInfo")
    @ResponseBody
    public Map allInfo(UserandVip userandVip, @RequestParam("page") int  page, @RequestParam("limit") int limit){
        System.out.println(userandVip);

            /*DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            try {
                if(userandVip.getEndDateString() != null){
                    userandVip.setEndDate(format.parse(userandVip.getEndDateString()));
                    //format.format(userandVip.getEndDate());
                }
                if(userandVip.getStartDateString() != null){
                    userandVip.setStartDate(format.parse(userandVip.getStartDateString()));
                    //format.format(userandVip.getStartDate());
                }

                System.out.println(userandVip);
            } catch (ParseException e) {
                e.printStackTrace();
            }*/


        List<UserandVip> list = userVipInfoServiceImp.queryAll1(userandVip);
        Map map = PageUtil.page(list,limit,page);
        return map;
    }

    //删除选中用户信息
    @RequestMapping("/vip/deleteSingle")
    @ResponseBody
    public String deleteSingle(Integer id){
        return userVipInfoServiceImp.deleUserVipInfo(id);
    }
    //开通VIP
    @RequestMapping("/vip/addVip")
    @ResponseBody
    public String addVip(UserandVip userandVip){
        System.out.println(userandVip);
        String message  = userVipInfoServiceImp.openVip(userandVip);
        return message;

    }

    //获取所有VIP套餐信息
    @RequestMapping("/vip/showVip")
    @ResponseBody
    public List<CinemaVip> showVip(){
        return cinemaVipServiceImp.showAllVip();
    }

    //搜索
    @RequestMapping("/vip/search")
    @ResponseBody
    public String  search(UserandVip userandVip){

        return "";
    }

    //搜索
    @RequestMapping("/vip/changeVip")
    @ResponseBody
    public String  changeVip(HttpSession session){
        UsersInfo  usersInfo = (UsersInfo) session.getAttribute("user");

        return "";
    }

}
